- name: setup the database
  hosts: db01.iad2.fedoraproject.org:db01.stg.iad2.fedoraproject.org
  gather_facts: no
  become: yes
  become_user: postgres
  vars_files:
  - /srv/web/infra/ansible/vars/global.yml
  - /srv/private/ansible/vars.yml
  - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml

  tasks:
  - name: elections DB user
    postgresql_user:
      name: "{{ elections_db_user }}"
      password: "{{ elections_db_pass }}"
  - name: elections database creation
    postgresql_db:
      name: "{{ elections_db_name }}"
      owner: "{{ elections_db_user }}"
      encoding: UTF-8


- name: make the app be real
  hosts: os_control_stg[0]:os_control[0]
  user: root
  gather_facts: False

  vars_files:
    - /srv/web/infra/ansible/vars/global.yml
    - "/srv/private/ansible/vars.yml"
    - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml

  roles:
  - role: rabbit/user
    username: "elections{{ env_suffix }}"
    sent_topics: ^org\.fedoraproject\.{{ env_short }}\.fedora_elections\..*

  - role: openshift/project
    app: elections
    description: Fedora Elections apps
    appowners:
    - cverna
    - pingou
    - bcotton
    tags:
    - appowners

  - role: openshift/keytab
    app: elections
    key: service.keytab
    secret_name: elections-keytab
    service: HTTP
    host: "elections{{ env_suffix }}.fedoraproject.org"

  - role: openshift/ipa-client
    app: elections

  - role: openshift/object
    app: elections
    template: imagestream.yml
    objectname: imagestream.yml

  - role: openshift/object
    app: elections
    template: buildconfig.yml
    objectname: buildconfig.yml

  - role: openshift/secret-file
    app: elections
    secret_name: elections-fedora-messaging-key
    key: elections.key
    privatefile: "rabbitmq/{{env}}/pki/private/elections{{env_suffix}}.key"

  - role: openshift/secret-file
    app: elections
    secret_name: elections-fedora-messaging-crt
    key: elections.crt
    privatefile: "rabbitmq/{{env}}/pki/issued/elections{{env_suffix}}.crt"

  - role: openshift/secret-file
    app: elections
    secret_name: elections-fedora-messaging-ca
    key: elections.ca
    privatefile: "rabbitmq/{{env}}/pki/ca.crt"

  - role: openshift/object
    app: elections
    template: secret.yml
    objectname: secret.yml

  - role: openshift/object
    app: elections
    template: configmap.yml
    objectname: configmap.yml

  - role: openshift/start-build
    app: elections
    buildname: elections-build
    objectname: elections-build

  - role: openshift/object
    app: elections
    file: service.yml
    objectname: service.yml

  - role: openshift/route
    app: elections
    routename: elections
    host: "elections{{ env_suffix }}.fedoraproject.org"
    serviceport: 8000-tcp
    servicename: elections

  - role: openshift/object
    app: elections
    file: deploymentconfig.yml
    objectname: deploymentconfig.yml
